#include "Rp2Renderer.h"

using namespace Rp2;

GLenum Renderer::ms_aeFrontFace[CullState::FT_QUANTITY] =
{
    GL_CCW,
    GL_CW
};

GLenum Renderer::ms_aeCullFace[CullState::CT_QUANTITY] =
{
    GL_FRONT,
    GL_BACK
};

//---------------------------------------------------------------------------------------------------
void Renderer::SetCullState(CullState* pkCullState)
{
    m_aspkState[GlobalState::CULL] = pkCullState;

	if (pkCullState->Enabled)
	{
		glEnable(GL_CULL_FACE);
	}
	else
	{
		glDisable(GL_CULL_FACE);
	}

	glFrontFace(ms_aeFrontFace[pkCullState->FrontFace]);

	if (!m_bReverseCullFace)
	{
		glCullFace(ms_aeCullFace[pkCullState->CullFace]);
	}
	else
	{
        if (ms_aeCullFace[pkCullState->CullFace] == GL_BACK)
        {
            glCullFace(GL_FRONT);
        }
        else
        {
            glCullFace(GL_BACK);
        }
	}
}
//---------------------------------------------------------------------------------------------------